"use strict";
var express = require('express');
var router = express.Router();
const qiniu = require("qiniu");
var bucket = 'huayuehai';
var accessKey = 'xK5ZiI5Nb5dUs9t_g9l21U0aPXZ3isqBlQTsQX6s';
var secretKey = 'y54tZc1UQXAOdxQDJd8VHKSNYWq3kUKEd_RGYLoT';
router.get('/qiniu/loadtokie', function (req, res, next) {
    var json =
        {
            "code": "1",
            "succeed": "succeed",
            "content": {
                "uploadToken": "密码错误"
            }
        };

    var mac = new qiniu.auth.digest.Mac(accessKey, secretKey);
    var options = {
        scope: bucket,
    };
    var putPolicy = new qiniu.rs.PutPolicy(options);
    var uploadToken=putPolicy.uploadToken(mac);
    json.content.uploadToken=uploadToken;
    res.send(json);
});

//http://www.cnblogs.com/diligenceday/p/5503777.html
// export function deleteQiNiuFile(key) {
//     var mac = new qiniu.auth.digest.Mac(accessKey, secretKey);
//     var config = new qiniu.conf.Config();
//     var bucketManager = new qiniu.rs.BucketManager(mac, config);
//     bucketManager.delete(bucket, key, function(err, respBody, respInfo) {
//         if (err) {
//             console.log(err);
//         } else {
//             console.log(respInfo.statusCode);
//             console.log(respBody);
//         }
//     });
//
//
// };

module.exports = router;
